<?php
class Application_Model_Filter_ReturnGoodsSearch {
    /**
     * 快速搜索
     */
    public $quick;
    /**
     * 状态
     */
    public $status;
    /**
     * 类型
     */
    public $type;
    /**
     * 开始时间
     */
    public $starttime;
    /**
     * 结束时间
     */
    public $endtime;
    /**
     * 是否删除
     */
    public $isDelete;
    /**
     * 是否超期
     */
    public $beyond;
    /**
     * 异常
     */
    public $problem;
    
    
    function getSearchFileds() {
        $where=array(); 
        $and = "";
        $problem = true;
        if($this->quick != NULL){
            $userItem = Application_Model_User::getByNikeNameStore($this->quick);
            $storeItem = Application_Model_StoreItem::surebybarcode($this->quick);
            if($userItem){
                $userarrid = "";
                foreach ($userItem as $uservalue) {
                    $userarrid.= $uservalue->id.",";
                }
                $where[$and." userid in "] = "(".$userarrid."0)";
                $and = " or ";
            }
            $where[$and." productName like "] = "%".$this->quick."%";
            $where[" or logisticsName like "] = "%".$this->quick."%";
            $where[" or logistics like "] = "%".$this->quick."%";
            if($storeItem){
                $where[" or storeItemId = "] = $storeItem->id;
            }
            $and = " and ";
            $problem = false;
        }
        if($this->type != NULL){
            $where[$and." type = "] = $this->type;
            $and = " and ";
        }
        if($this->status != NULL){
            $where[$and." status = "] = $this->status;
            $and = " and ";
        }
        if ($this->starttime != NULL) {
            $where[$and . ' datetime >= '] = $this->starttime;
            $and = ' and ';
        }
        if ($this->endtime != NULL) {
            $where[$and . ' datetime <= '] = $this->endtime." 23:59:59";
            $and = ' and ';
        }
        if($this->beyond == 1){
            $where[$and." status != "] = Application_Model_ReturnGoods::STATUS_Succeed;
            $where[$and . ' dotime >= '] = $this->starttime;
            $where[$and . ' dotime <= '] = $this->endtime." 23:59:59";
            $and = " and ";
        }
        if($problem){
            if($this->problem){
                $where[$and." problem = "] = $this->problem;
                $and = " and ";
            } else {
                $where[$and.' (problem is null or problem = 2) and 1='] = 1;
                $and = ' and ';
            }
        }
        if($this->isDelete == 1){
            $where[$and.' isDelete = '] = 1;
            $and = ' and ';
        }else{
            $where[$and.'( isDelete is null or isDelete = 0) and 1='] = 1;
            $and = ' and ';
        }            
        return $where;
    }
        
        
}


